﻿using System;
using System.Drawing;

namespace Hedgehog
{
    public static class TriangleHelper
    {
        public static bool CheckIfPointInsideTriangle(Point a, Point b, Point c, Point p)
        {
            if (Math.Abs(TriangleArea(a, b, p) + TriangleArea(a, c, p) + TriangleArea(b, c, p) - TriangleArea(a, b, c)) < 1E-2)
                return true;
            return false;
        }

        public static double Length(Point p1, Point p2)
        {
            return Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2));
        }

        public static double TriangleArea (Point a,Point b, Point c)
        {
            double p = (Length(a, b) + Length(b, c) + Length(a, c))/2;
            return Math.Sqrt(p*(p - Length(a, b))*(p - Length(b, c))*(p - Length(a, c)));
        }
    }
}